package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumTrackListVo;
import com.atguigu.tingshu.vo.album.TrackInfoVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/***
 * 声音
 */

@Tag(name = "声音管理")
@RestController
@RequestMapping("/api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

    @Autowired
    private TrackInfoService trackInfoService;

    /**
     * 上传声音
     *
     * @param file
     * @return
     */
    @GuiGuLogin
    @PostMapping("/uploadTrack")
    public Result uploadTrack(@RequestBody MultipartFile file) {
        return Result.ok(trackInfoService.uploadTrack(file));
    }

    /**
     * 保存声音
     *
     * @param trackInfoVo
     * @return
     */
    @GuiGuLogin
    @PostMapping("/saveTrackInfo")
    public Result saveTrackInfo(@RequestBody @Validated TrackInfoVo trackInfoVo) {
        trackInfoService.saveTrackInfo(trackInfoVo);
        return Result.ok();
    }

    /**
     * 分页查询声音
     *
     * @param trackInfoQuery
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GuiGuLogin
    @PostMapping("/findUserTrackPage/{pageNum}/{pageSize}")
    public Result findUserTrackPage(@RequestBody TrackInfoQuery trackInfoQuery,
                                    @PathVariable("pageNum") Long pageNum,
                                    @PathVariable("pageSize") Long pageSize) {
        return Result.ok(trackInfoService.findUserTrackPage(trackInfoQuery, pageNum, pageSize));
    }

    /**
     * 删除声音
     *
     * @param trackId
     * @return
     */
    @GuiGuLogin
    @DeleteMapping("/removeTrackInfo/{trackId}")
    public Result removeTrackInfo(@PathVariable("trackId") Long trackId) {
        trackInfoService.removeTrackInfo(trackId);
        return Result.ok();
    }

    /**
     * 编辑数据回显
     *
     * @param trackId
     * @return
     */
    @GuiGuLogin
    @GetMapping("/getTrackInfo/{trackId}")
    public Result getTrackInfo(@PathVariable("trackId") Long trackId) {
        return Result.ok(trackInfoService.getById(trackId));
    }

    /**
     * 更新声音
     *
     * @param trackId
     * @return
     */
    @GuiGuLogin
    @PutMapping("/updateTrackInfo/{trackId}")
    public Result updateTrackInfo(@PathVariable("trackId") Long trackId, @RequestBody @Validated TrackInfoVo trackInfoVo) {
        trackInfoService.updateTrackInfo(trackId, trackInfoVo);
        return Result.ok();
    }

    /**
     * 分页查询声音列表
     * @param albumId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GuiGuLogin
    @GetMapping("/findAlbumTrackPage/{albumId}/{pageNum}/{pageSize}")
    public Result<IPage<AlbumTrackListVo>> findAlbumTrackPage(@PathVariable(value = "albumId") Long albumId,
                                                              @PathVariable(value = "pageNum") Integer pageNum ,
                                                              @PathVariable(value = "pageSize") Integer pageSize) {
        return Result.ok(trackInfoService.findAlbumTrackPage(albumId, pageNum, pageSize));
    }


}

